

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="分享开发的趣事">
  <meta name="author" content="RoseC(陈智豪)">
  <meta name="keywords" content="RoseC的博客,陈智豪,RoseC">
  <meta name="baidu-site-verification" content="code-2LJIrA8S4z" />
  <title>无缝轮播图 - RoseC的博客</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.5.3/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.1.2/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"rose-ccc.gitee.io","root":"/","version":"1.8.5","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"copy_btn":true,"image_zoom":{"enable":true},"lazyload":{"enable":true,"onlypost":false},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null}}};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>RoseC</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/indexImg/index.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="无缝轮播图">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-12-05 16:47" pubdate>
        2020年12月5日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      609 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      10
       分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">无缝轮播图</h1>
            
              <p class="note note-info">
                
                  本文最后更新于：2021年3月3日 凌晨
                
              </p>
            
            <div class="markdown-body">
              <p>轮播图原理如下：<br><img src="/2020/12/05/%E6%97%A0%E7%BC%9D%E8%BD%AE%E6%92%AD%E5%9B%BE/lunbo.png" srcset="/img/loading.gif"><br>第四第五步正常来说是不能有延迟的，因为是同一张图<br>代码如下：</p>
<h4 id="HTML"><a href="#HTML" class="headerlink" title="HTML"></a>HTML</h4><pre><code class="hljs bash">&lt;div id=<span class="hljs-string">&quot;out&quot;</span>&gt;
	&lt;div id=<span class="hljs-string">&quot;imgbox&quot;</span>&gt;
		&lt;img src=<span class="hljs-string">&quot;./4.jpg&quot;</span> /&gt;
		&lt;img src=<span class="hljs-string">&quot;./1.jpg&quot;</span> /&gt;
		&lt;img src=<span class="hljs-string">&quot;./2.jpg&quot;</span> /&gt;
		&lt;img src=<span class="hljs-string">&quot;./3.jpg&quot;</span> /&gt;
		&lt;img src=<span class="hljs-string">&quot;./4.jpg&quot;</span> /&gt;
		&lt;img src=<span class="hljs-string">&quot;./1.jpg&quot;</span> /&gt;
	&lt;/div&gt;
&lt;/div&gt;</code></pre>
<h4 id="Css"><a href="#Css" class="headerlink" title="Css"></a>Css</h4><pre><code class="hljs bash"><span class="hljs-comment">#out &#123;</span>
	position: relative;
	width: 100px;
	height: 100px;
	border: 5px solid lightcoral;
	overflow: hidden;
	margin: auto;
&#125;

<span class="hljs-comment">#imgbox &#123;</span>
	position: absolute;
	left: -100px;
	width: 600px;
	background-color: lightblue;
	display: flex;
	flex-direction: row;
&#125;

<span class="hljs-comment">#imgbox img &#123;</span>
	width: 100px;
	height: 100px;
	display: block;
&#125;</code></pre>
<h4 id="Javascript"><a href="#Javascript" class="headerlink" title="Javascript"></a>Javascript</h4><pre><code class="hljs bash"><span class="hljs-built_in">let</span> box = document.getElementById(<span class="hljs-string">&quot;imgbox&quot;</span>)
<span class="hljs-built_in">let</span> temp = 0
<span class="hljs-keyword">function</span> <span class="hljs-function"><span class="hljs-title">lunbo</span></span>() &#123;
	<span class="hljs-keyword">if</span> (temp == -500) &#123;
		temp = -100
		box.style.transition = <span class="hljs-string">&quot;none&quot;</span>
		box.style.left = <span class="hljs-string">&quot;-100px&quot;</span>
		setTimeout(<span class="hljs-function"><span class="hljs-title">function</span></span>()&#123; //这里使用setTimeout是为了执行下面的函数，否则第四第五步会有延迟
			temp -= 100
			box.style.left = temp + <span class="hljs-string">&quot;px&quot;</span>
			box.style.transition = <span class="hljs-string">&quot;all .5s&quot;</span>
			&#125;,0)
		&#125; <span class="hljs-keyword">else</span> &#123;
			temp -= 100
			box.style.left = temp + <span class="hljs-string">&quot;px&quot;</span>
			box.style.transition = <span class="hljs-string">&quot;all .5s&quot;</span>
		&#125;
	&#125;
<span class="hljs-built_in">let</span> act = setInterval(lunbo, 1000)</code></pre>

<h3 id="2021-3-3新增"><a href="#2021-3-3新增" class="headerlink" title="2021/3/3新增"></a>2021/3/3新增</h3><p>最近发现一个更加人性话的方法来消除延迟，通过监听图组的transitionend实现（没错，就是动画事件，阅读红宝石后学到的/(ㄒoㄒ)/~~），这次通过Vue实现</p>
<pre><code class="hljs bash">&lt;template&gt;
	&lt;div id=<span class="hljs-string">&quot;imgGroup&quot;</span> ref=<span class="hljs-string">&quot;imgGroup&quot;</span>&gt;
		&lt;div class=<span class="hljs-string">&quot;imgOut&quot;</span>&gt;&lt;img src=<span class="hljs-string">&quot;../static/sights/4.png&quot;</span> /&gt;&lt;/div&gt;
		&lt;div class=<span class="hljs-string">&quot;imgOut&quot;</span>&gt;&lt;img src=<span class="hljs-string">&quot;../static/sights/1.png&quot;</span> /&gt;&lt;/div&gt;
		&lt;div class=<span class="hljs-string">&quot;imgOut&quot;</span>&gt;&lt;img src=<span class="hljs-string">&quot;../static/sights/2.png&quot;</span> /&gt;&lt;/div&gt;
		&lt;div class=<span class="hljs-string">&quot;imgOut&quot;</span>&gt;&lt;img src=<span class="hljs-string">&quot;../static/sights/3.png&quot;</span> /&gt;&lt;/div&gt;
		&lt;div class=<span class="hljs-string">&quot;imgOut&quot;</span>&gt;&lt;img src=<span class="hljs-string">&quot;../static/sights/4.png&quot;</span> /&gt;&lt;/div&gt;
	&lt;/div&gt;
&lt;/template&gt;

&lt;script&gt;
	<span class="hljs-built_in">export</span> default &#123;
		<span class="hljs-function"><span class="hljs-title">data</span></span>() &#123;
			<span class="hljs-built_in">return</span> &#123;
				page: 1,
				<span class="hljs-built_in">type</span>: <span class="hljs-string">&#x27;&#x27;</span>
			&#125;
		&#125;,
		<span class="hljs-function"><span class="hljs-title">mounted</span></span>() &#123;
			this.type = this.getQueryString(<span class="hljs-string">&#x27;type&#x27;</span>)
			this.<span class="hljs-variable">$refs</span>.imgGroup.style.top = <span class="hljs-string">&quot;-560px&quot;</span>
			<span class="hljs-built_in">let</span> imgMove = setInterval(this.nextImg, 3000)
			imgMove
			this.<span class="hljs-variable">$refs</span>.imgGroup.addEventListener(<span class="hljs-string">&quot;transitionend&quot;</span>, () =&gt; &#123;
				<span class="hljs-keyword">if</span> (this.page == 4) &#123;
					this.backImg()
				&#125;
			&#125;)
			this.<span class="hljs-variable">$refs</span>.imgGroup.onmouseover = () =&gt; &#123;
				clearInterval(imgMove)
			&#125;
			this.<span class="hljs-variable">$refs</span>.imgGroup.onmouseout = () =&gt; &#123;
				imgMove = setInterval(this.nextImg, 3000)
			&#125;
		&#125;,
		methods: &#123;
			<span class="hljs-function"><span class="hljs-title">nextImg</span></span>() &#123;
				this.<span class="hljs-variable">$refs</span>.imgGroup.style.transition = <span class="hljs-string">&quot;all .5s&quot;</span>
				<span class="hljs-built_in">let</span> temp = parseInt(this.<span class="hljs-variable">$refs</span>.imgGroup.style.top)
				this.<span class="hljs-variable">$refs</span>.imgGroup.style.top = temp - 560 + <span class="hljs-string">&quot;px&quot;</span>
				this.page++
			&#125;,
			<span class="hljs-function"><span class="hljs-title">backImg</span></span>() &#123;
				this.<span class="hljs-variable">$refs</span>.imgGroup.style.transition = <span class="hljs-string">&quot;none&quot;</span>
				this.<span class="hljs-variable">$refs</span>.imgGroup.style.top = 0 + <span class="hljs-string">&quot;px&quot;</span>
				this.page = 0
			&#125;,
			change(e) &#123;
				this.type = e
			&#125;
		&#125;
	&#125;
&lt;/script&gt;

&lt;style&gt;
	自行脑补充，嘻嘻(●<span class="hljs-string">&#x27;◡&#x27;</span>●)，（其实就是懒，不想把代码抽出来）
&lt;/style&gt;</code></pre>


            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E5%89%8D%E7%AB%AF/">前端</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Javascript/">Javascript</a>
                    
                      <a class="hover-with-bg" href="/tags/Html/">Html</a>
                    
                      <a class="hover-with-bg" href="/tags/Css/">Css</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/01/07/Javascript%E6%B7%B1%E6%B5%85%E6%8B%B7%E8%B4%9D%E9%97%AE%E9%A2%98/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Javascript深浅拷贝问题</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/11/29/centos%E9%83%A8%E7%BD%B2node-mongodb%E7%8E%AF%E5%A2%83/">
                        <span class="hidden-mobile">centos部署node+mongodb环境</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>

<!-- SCRIPTS -->

  <script  src="https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":200})
    NProgress.start()
    document.addEventListener('DOMContentLoaded', function() {
      window.NProgress && window.NProgress.inc();
    })
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.5.3/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  



  <script  src="https://cdn.staticfile.org/tocbot/4.12.0/tocbot.min.js" ></script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.3.0/anchor.min.js" ></script>



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    (function () {
      var path = "/local-search.xml";
      var inputArea = document.querySelector("#local-search-input");
      inputArea.onclick = function () {
        searchFunc(path, 'local-search-input', 'local-search-result');
        this.onclick = null
      }
    })()
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>



</body>
</html>
